package com.lego.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lego.bean.CommonResult;
import com.lego.service.ReviewsService;
import com.lego.service.impl.ReviewsServiceImpl;
@WebServlet("/delConmentServlet")
public class DelConmetServlet extends HttpServlet {
	ReviewsService rs = new ReviewsServiceImpl();
    private ObjectMapper om = new ObjectMapper();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
            throws ServletException, IOException {
        CommonResult result = new CommonResult();
        try {
            int reviewId = Integer.parseInt(req.getParameter("reviewId"));
            int rows = rs.deleteCmt(reviewId);
            
            if (rows > 0) {
                result.setCode(200);
                result.setMessage("删除成功");
            } else {
                result.setCode(500);
                result.setMessage("评论不存在或删除失败");
            }
        } catch (Exception e) {
            result.setCode(500);
            result.setMessage("服务器错误: " + e.getMessage());
        }
        
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(om.writeValueAsString(result));
    }
}
